package net.neptech.repository;

import net.neptech.model.ipc.SensitiveWord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author HuangZhengmin
 * @desc
 * @Date 2025/8/20 15:32
 * @Version 1.0
 */
@Repository
public interface SensitiveWordRepository extends JpaRepository<SensitiveWord, Long> {

  /**
   * 根据敏感词查找
   * @param word 敏感词
   * @return 敏感词列表
   */
  List<SensitiveWord> findByWord(String word);

  /**
   * 根据分类查找
   * @param category 分类
   * @return 敏感词列表
   */
  List<SensitiveWord> findByCategory(String category);

  /**
   * 根据关键词模糊搜索
   * @param keyword 关键词
   * @return 敏感词列表
   */
  @Query("SELECT sw FROM SensitiveWord sw WHERE sw.word LIKE %:keyword%")
  List<SensitiveWord> findByWordContaining(@Param("keyword") String keyword);

  /**
   * 获取所有分类
   * @return 分类列表
   */
  @Query("SELECT DISTINCT sw.category FROM SensitiveWord sw")
  List<String> findAllCategories();
}
